import { Module } from '@nestjs/common';
import { MongooseModule } from '@nestjs/mongoose';
import { User, UserSchema } from '../schemas/users/user.schema';
import { AuthService } from './auth.service';
import { AuthController } from './auth.controller';
import { JwtModule } from '@nestjs/jwt';
import { ConfigModule, ConfigService } from '@nestjs/config';
import { RolesGuard } from './guards/roles.guard'; // 导入角色守卫
import { JwtAuthGuard } from './guards/jwt-auth.guard'; // 导入 JWT 守卫
import { PassportModule } from '@nestjs/passport';
import { JwtStrategy } from './jwt.strategy'; // 引入 JwtStrategy
@Module({
  imports: [
    MongooseModule.forFeature([{ name: User.name, schema: UserSchema }]),
    JwtModule.registerAsync({
      imports: [ConfigModule],
      inject: [ConfigService],
      useFactory: async (configService: ConfigService) => ({
        secret: configService.get<string>('JWT_SECRET'),
        signOptions: { expiresIn: '60m' },
      }),
    }),
    PassportModule.register({ defaultStrategy: 'jwt' }
    ), // 注册 Passport 模块
  ],
  providers: [AuthService,RolesGuard,JwtAuthGuard,JwtStrategy],
  controllers: [AuthController],
  exports: [AuthService, JwtAuthGuard, JwtAuthGuard,JwtStrategy], // 导出 AuthService
})
export class AuthModule { }